import requests
import random
import redis
from twisted.words.protocols.jabber.jstrports import client


def have_requests(url):
    client = redis.StrictRedis(host='localhost', port=6379, db=0)
    urls = client.lrange('zlpq', 0, -1)
    client.close()
    return url.encode() in urls


def save_requests(url):
    client = redis.StrictRedis(host='localhost', port=6379, db=0)
    client.lpush('zlpq',url)
    client.close()

urls = [f"https://httpbin.org/get?age={random.randint(1,100)}" for i in range(10)]
# urls = set(urls)

for url in urls:
    if  not have_requests(url):
        response = requests.get(url)
        print(response)
        save_requests(url)
    else:
        print('已经爬取过l')
